<template name="detail">
	<view>
		<cu-custom bgColor="bg-white" :isBack="true"><block slot="content">个人信息</block></cu-custom>
		<view class="cu-list menu margin-top">
			<view class="cu-item">
				<view class="content">
					<text class="text-grey">头像</text>
				</view>
				<view class="action" @click="changeAvatar">
					<image class="cu-avatar radius xs" :src="member.avatar" style="background-image:url(../../../static/logo.png);"></image>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="text-grey">名称</text>
				</view>
				<view class="action">
					<text class="text-grey text-sm">{{member.nickName}}</text>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					<text class="text-grey">手机</text>
				</view>
				<view class="action">
					<text class="text-grey text-sm">{{member.phonenumber}}</text>
				</view>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-grey margin-top-xl lg" @click="loginOut" >退出</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				member:uni.getStorageSync('member'),
			}
		},
		methods: {
			previewImage(){
				let self=this
				uni.previewImage({
					urls:[
						self.member.qrcode,
					],  
					current:0  
				}) 
			},
			changeAvatar(){
				let self =this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
					 self.bblosApi.commonApi.uploadFile( res.tempFilePaths[0],{}).then(res=>{
							let resdata=JSON.parse(res.data)
							let data={
								memberId:self.member.memberId,
								avatar:resdata.url
							}
							self.bblosApi.memberApi.updateMember(data).then(res=>{
								self.member.avatar=resdata.url
								uni.setStorageSync('member',self.member)
							})
							
					  })
					} 
				});
			}
			,
			loginOut(){
				uni.clearStorage();
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style>
	.mine-top{
		height: 160upx;
		display: flex;
		align-items: center;
	}
	.mine{
		width: 100%;
		color: #FFFFFF;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}
</style>
